package cn.iocoder.yudao.module.design.dal.mysql.node;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.design.controller.admin.node.vo.NodeBaseVO;
import cn.iocoder.yudao.module.design.controller.admin.node.vo.NodeExportReqVO;
import cn.iocoder.yudao.module.design.controller.admin.node.vo.NodePageReqVO;
import cn.iocoder.yudao.module.design.dal.dataobject.node.NodeDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * 任务节点信息 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface NodeMapper extends BaseMapperX<NodeDO> {

    default PageResult<NodeDO> selectPage(NodePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<NodeDO>()
                .eqIfPresent(NodeDO::getHouseId, reqVO.getHouseId())
                .eqIfPresent(NodeDO::getDesignerId, reqVO.getDesignerId())
                .eqIfPresent(NodeDO::getDealerId, reqVO.getDealerId())
                .eqIfPresent(NodeDO::getContentCd, reqVO.getContentCd())
                .eqIfPresent(NodeDO::getPreId, reqVO.getPreId())
                .eqIfPresent(NodeDO::getNextIds, reqVO.getNextIds())
                .eqIfPresent(NodeDO::getMustIds, reqVO.getMustIds())
                .eqIfPresent(NodeDO::getStatusCd, reqVO.getStatusCd())
                .eqIfPresent(NodeDO::getCost, reqVO.getCost())
                .eqIfPresent(NodeDO::getPicId, reqVO.getPicId())
                .eqIfPresent(NodeDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(NodeDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(NodeDO::getFinishTime, reqVO.getFinishTime())
                .eqIfPresent(NodeDO::getCreator, reqVO.getCreator())
                .eqIfPresent(NodeDO::getUpdater, reqVO.getUpdater())
                .betweenIfPresent(NodeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(NodeDO::getId));
    }

    default List<NodeDO> selectList(NodeExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<NodeDO>()
                .eqIfPresent(NodeDO::getHouseId, reqVO.getHouseId())
                .eqIfPresent(NodeDO::getDesignerId, reqVO.getDesignerId())
                .eqIfPresent(NodeDO::getDealerId, reqVO.getDealerId())
                .eqIfPresent(NodeDO::getContentCd, reqVO.getContentCd())
                .eqIfPresent(NodeDO::getPreId, reqVO.getPreId())
                .eqIfPresent(NodeDO::getNextIds, reqVO.getNextIds())
                .eqIfPresent(NodeDO::getMustIds, reqVO.getMustIds())
                .eqIfPresent(NodeDO::getStatusCd, reqVO.getStatusCd())
                .eqIfPresent(NodeDO::getCost, reqVO.getCost())
                .eqIfPresent(NodeDO::getPicId, reqVO.getPicId())
                .eqIfPresent(NodeDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(NodeDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(NodeDO::getFinishTime, reqVO.getFinishTime())
                .eqIfPresent(NodeDO::getCreator, reqVO.getCreator())
                .eqIfPresent(NodeDO::getUpdater, reqVO.getUpdater())
                .betweenIfPresent(NodeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(NodeDO::getId));
    }
    default List<NodeDO> selectList(NodeBaseVO baseVO) {
        return selectList(new LambdaQueryWrapperX<NodeDO>()
                .eqIfPresent(NodeDO::getFlowId, baseVO.getFlowId())
                .eqIfPresent(NodeDO::getHouseId, baseVO.getHouseId())
                .eqIfPresent(NodeDO::getDesignerId, baseVO.getDesignerId())
                .eqIfPresent(NodeDO::getDealerId, baseVO.getDealerId())
                .eqIfPresent(NodeDO::getContentCd, baseVO.getContentCd())
                .eqIfPresent(NodeDO::getPreId, baseVO.getPreId())
                .eqIfPresent(NodeDO::getNextIds, baseVO.getNextIds())
                .eqIfPresent(NodeDO::getMustIds, baseVO.getMustIds())
                .eqIfPresent(NodeDO::getStatusCd, baseVO.getStatusCd())
                .eqIfPresent(NodeDO::getCost, baseVO.getCost())
                .eqIfPresent(NodeDO::getPicId, baseVO.getPicId())
                .eqIfPresent(NodeDO::getRemark, baseVO.getRemark())
                .eqIfPresent(NodeDO::getCreator, baseVO.getCreator())
                .eqIfPresent(NodeDO::getUpdater, baseVO.getUpdater())
                .orderByAsc(NodeDO::getId));
    }
    default List<NodeDO> selectListByFlowId(Long flowId) {
        return selectList(new LambdaQueryWrapperX<NodeDO>()
                .eqIfPresent(NodeDO::getFlowId, flowId)
                .orderByAsc(NodeDO::getId));
    }
    /**
     * 根据节点id查询节点信息 项目名称  流程名称 节点名称 （id）
     * @param id
     * @return
     */
    Map<String,Object> getNodeInfoById(@Param("id") Long id );
}
